package net.maku.events.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.events.convert.ActivityQuestionBankOptionConvert;
import net.maku.events.entity.ActivityQuestionBankOptionEntity;
import net.maku.events.service.ActivityQuestionBankOptionService;
import net.maku.events.query.ActivityQuestionBankOptionQuery;
import net.maku.events.vo.ActivityQuestionBankOptionVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 题库题目选项
*
* @author 阿沐 babamu@126.com
* @since 1.0.0 2025-03-29
*/
@RestController
@RequestMapping("events/activity_question_bank_option")
@Tag(name="题库题目选项")
@AllArgsConstructor
public class ActivityQuestionBankOptionController {
    private final ActivityQuestionBankOptionService activityQuestionBankOptionService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('events:activity_question_bank_option:page')")
    public Result<PageResult<ActivityQuestionBankOptionVO>> page(@ParameterObject @Valid ActivityQuestionBankOptionQuery query){
        PageResult<ActivityQuestionBankOptionVO> page = activityQuestionBankOptionService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('events:activity_question_bank_option:page')")
    public Result<ActivityQuestionBankOptionVO> get(@PathVariable("id") Long id){
        ActivityQuestionBankOptionEntity entity = activityQuestionBankOptionService.getById(id);

        return Result.ok(ActivityQuestionBankOptionConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
    @PreAuthorize("hasAuthority('events:activity_question_bank_option:page')")
    public Result<String> save(@RequestBody ActivityQuestionBankOptionVO vo){
        activityQuestionBankOptionService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
    @PreAuthorize("hasAuthority('events:activity_question_bank_option:page')")
    public Result<String> update(@RequestBody @Valid ActivityQuestionBankOptionVO vo){
        activityQuestionBankOptionService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    @PreAuthorize("hasAuthority('events:activity_question_bank_option:page')")
    public Result<String> delete(@RequestBody List<Long> idList){
        activityQuestionBankOptionService.delete(idList);

        return Result.ok();
    }
}